﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace XFFSM
{
    public class GraphLayer
    {

        #region 字段

        protected Rect position; 

        #endregion

        #region 属性

        public FSMEditorWindow EditorWindow { get; private set; }
         

        #endregion


        #region 方法

        public GraphLayer(FSMEditorWindow editorWindow) {
            this.EditorWindow = editorWindow;
        }

        public virtual void OnGUI(Rect rect) {
            position = rect;
            UpdateTransformationMatrix();
        }

        public virtual void ProcessEvents() { 
            
        }

        public virtual void Update() { }

        private void UpdateTransformationMatrix() 
        {
            //this.transormMatrix = Matrix4x4.TRS(position.center + this.Context.DragOffset  , Quaternion.identity,Vector3.one * this.Context.ZoomFactor);
        }

        public Rect GetTransformedRect(Rect rect) {
            Rect result = new Rect();
            result.position = Context.Instance.GetMatrixInfo(position).matrix.MultiplyPoint(rect.position);
            result.size = Context.Instance.GetMatrixInfo(position).matrix.MultiplyVector(rect.size);

            return result;
        }

        public virtual void OnLostFocus()
        {
            if (UnityEditor.EditorWindow.mouseOverWindow != null && UnityEditor.EditorWindow.mouseOverWindow.GetType().ToString().Equals("UnityEditor.InspectorWindow"))
                return;
            Context.Instance.ClearSelections();
        }

        #endregion
    }

}

